home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Interfaces / PInterfaces / Threads.p < prev    next >
Encoding:
Text File  |  1994-11-11  |  6.7 KB  |  236 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        Threads.p
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a3  ETO #16, MPW prerelease.  Friday, November 11, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. }
  16.  
  17. {$IFC UNDEFINED UsingIncludes}
  18. {$SETC UsingIncludes := 0}
  19. {$ENDC}
  20.  
  21. {$IFC NOT UsingIncludes}
  22.  UNIT Threads;
  23.  INTERFACE
  24. {$ENDC}
  25.  
  26. {$IFC UNDEFINED __THREADS__}
  27. {$SETC __THREADS__ := 1}
  28.  
  29. {$I+}
  30. {$SETC ThreadsIncludes := UsingIncludes}
  31. {$SETC UsingIncludes := 1}
  32.  
  33.  
  34. {$IFC UNDEFINED __ERRORS__}
  35. {$I Errors.p}
  36. {$ENDC}
  37. {    ConditionalMacros.p                                            }
  38.  
  39. {$IFC UNDEFINED __MEMORY__}
  40. {$I Memory.p}
  41. {$ENDC}
  42. {    Types.p                                                        }
  43. {    MixedMode.p                                                    }
  44.  
  45. {$PUSH}
  46. {$ALIGN MAC68K}
  47. {$LibExport+}
  48.     
  49. TYPE
  50.     ThreadState = INTEGER;
  51.  
  52.  
  53. CONST
  54.     kReadyThreadState            = 0;
  55.     kStoppedThreadState            = 1;
  56.     kRunningThreadState            = 2;
  57.  
  58. { Error codes have been meoved to Errors.(pah) }
  59. { Thread environment characteristics }
  60.     
  61. TYPE
  62.     ThreadTaskRef = Ptr;
  63.  
  64. { Thread characteristics }
  65.     ThreadStyle = LONGINT;
  66.  
  67.  
  68. CONST
  69.     kCooperativeThread            = 1 * (2**(0));
  70.     kPreemptiveThread            = 1 * (2**(1));
  71.  
  72. { Thread identifiers }
  73.     
  74. TYPE
  75.     ThreadID = LONGINT;
  76.  
  77.  
  78. CONST
  79.     kNoThreadID                    = 0;
  80.     kCurrentThreadID            = 1;
  81.     kApplicationThreadID        = 2;
  82.  
  83. { Options when creating a thread }
  84.     
  85. TYPE
  86.     ThreadOptions = LONGINT;
  87.  
  88.  
  89. CONST
  90.     kNewSuspend                    = 0+(1 * (2**(0)));
  91.     kUsePremadeThread            = 0+(1 * (2**(1)));
  92.     kCreateIfNeeded                = 0+(1 * (2**(2)));
  93.     kFPUNotNeeded                = 0+(1 * (2**(3)));
  94.     kExactMatchThread            = 0+(1 * (2**(4)));
  95.  
  96. { Information supplied to the custom scheduler }
  97.  
  98. TYPE
  99.     SchedulerInfoRec = RECORD
  100.         InfoRecSize:            LONGINT;
  101.         CurrentThreadID:        ThreadID;
  102.         SuggestedThreadID:        ThreadID;
  103.         InterruptedCoopThreadID: ThreadID;
  104.     END;
  105.     SchedulerInfoRecPtr = ^SchedulerInfoRec;
  106.  
  107. {
  108.     The following ProcPtrs cannot be interchanged with UniversalProcPtrs because
  109.     of differences between 680x0 and PowerPC runtime architectures with regard to
  110.     the implementation of the Thread Manager.
  111.  }
  112. { Prototype for thread's entry (main) routine }
  113.     voidPtr = Ptr;
  114.  
  115.     ThreadEntryProcPtr = ProcPtr;  { FUNCTION (threadParam: UNIV Ptr): voidPtr; }
  116.  
  117. { Prototype for custom thread scheduler routine }
  118.     ThreadSchedulerProcPtr = ProcPtr;  { FUNCTION (schedulerInfo: SchedulerInfoRecPtr): ThreadID; }
  119.  
  120. { Prototype for custom thread switcher routine }
  121.     ThreadSwitchProcPtr = ProcPtr;  { PROCEDURE (threadBeingSwitched: ThreadID; switchProcParam: UNIV Ptr); }
  122.  
  123. { Prototype for thread termination notification routine }
  124.     ThreadTerminationProcPtr = ProcPtr;  { PROCEDURE (threadTerminated: ThreadID; terminationProcParam: UNIV Ptr); }
  125.  
  126. { Prototype for debugger NewThread notification }
  127.     DebuggerNewThreadProcPtr = ProcPtr;  { PROCEDURE (threadCreated: ThreadID); }
  128.  
  129. { Prototype for debugger DisposeThread notification }
  130.     DebuggerDisposeThreadProcPtr = ProcPtr;  { PROCEDURE (threadDeleted: ThreadID); }
  131.  
  132. { Prototype for debugger schedule notification }
  133.     DebuggerThreadSchedulerProcPtr = ProcPtr;  { FUNCTION (schedulerInfo: SchedulerInfoRecPtr): ThreadID; }
  134.  
  135. { Thread Manager routines }
  136.  
  137. FUNCTION CreateThreadPool(threadStyle: ThreadStyle; numToCreate: INTEGER; stackSize: Size): OSErr;
  138.     {$IFC NOT GENERATINGCFM}
  139.     INLINE $303C, $0501, $ABF2;
  140.     {$ENDC}
  141. FUNCTION GetFreeThreadCount(threadStyle: ThreadStyle; VAR freeCount: INTEGER): OSErr;
  142.     {$IFC NOT GENERATINGCFM}
  143.     INLINE $303C, $0402, $ABF2;
  144.     {$ENDC}
  145. FUNCTION GetSpecificFreeThreadCount(threadStyle: ThreadStyle; stackSize: Size; VAR freeCount: INTEGER): OSErr;
  146.     {$IFC NOT GENERATINGCFM}
  147.     INLINE $303C, $0615, $ABF2;
  148.     {$ENDC}
  149. FUNCTION GetDefaultThreadStackSize(threadStyle: ThreadStyle; VAR stackSize: Size): OSErr;
  150.     {$IFC NOT GENERATINGCFM}
  151.     INLINE $303C, $0413, $ABF2;
  152.     {$ENDC}
  153. FUNCTION ThreadCurrentStackSpace(thread: ThreadID; VAR freeStack: LONGINT): OSErr;
  154.     {$IFC NOT GENERATINGCFM}
  155.     INLINE $303C, $0414, $ABF2;
  156.     {$ENDC}
  157. FUNCTION NewThread(threadStyle: ThreadStyle; threadEntry: ThreadEntryProcPtr; threadParam: UNIV Ptr; stackSize: Size; options: ThreadOptions; threadResult: UNIV Ptr; VAR threadMade: ThreadID): OSErr;
  158.     {$IFC NOT GENERATINGCFM}
  159.     INLINE $303C, $0E03, $ABF2;
  160.     {$ENDC}
  161. FUNCTION DisposeThread(threadToDump: ThreadID; threadResult: UNIV Ptr; recycleThread: BOOLEAN): OSErr;
  162.     {$IFC NOT GENERATINGCFM}
  163.     INLINE $303C, $0504, $ABF2;
  164.     {$ENDC}
  165. FUNCTION YieldToThread(suggestedThread: ThreadID): OSErr;
  166.     {$IFC NOT GENERATINGCFM}
  167.     INLINE $303C, $0205, $ABF2;
  168.     {$ENDC}
  169. FUNCTION YieldToAnyThread: OSErr;
  170.     {$IFC NOT GENERATINGCFM}
  171.     INLINE $42A7, $303C, $0205, $ABF2;
  172.     {$ENDC}
  173. FUNCTION GetCurrentThread(VAR currentThreadID: ThreadID): OSErr;
  174.     {$IFC NOT GENERATINGCFM}
  175.     INLINE $303C, $0206, $ABF2;
  176.     {$ENDC}
  177. FUNCTION GetThreadState(threadToGet: ThreadID; VAR threadState: ThreadState): OSErr;
  178.     {$IFC NOT GENERATINGCFM}
  179.     INLINE $303C, $0407, $ABF2;
  180.     {$ENDC}
  181. FUNCTION SetThreadState(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  182.     {$IFC NOT GENERATINGCFM}
  183.     INLINE $303C, $0508, $ABF2;
  184.     {$ENDC}
  185. FUNCTION SetThreadStateEndCritical(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  186.     {$IFC NOT GENERATINGCFM}
  187.     INLINE $303C, $0512, $ABF2;
  188.     {$ENDC}
  189. FUNCTION SetThreadScheduler(threadScheduler: ThreadSchedulerProcPtr): OSErr;
  190.     {$IFC NOT GENERATINGCFM}
  191.     INLINE $303C, $0209, $ABF2;
  192.     {$ENDC}
  193. FUNCTION SetThreadSwitcher(thread: ThreadID; threadSwitcher: ThreadSwitchProcPtr; switchProcParam: UNIV Ptr; inOrOut: BOOLEAN): OSErr;
  194.     {$IFC NOT GENERATINGCFM}
  195.     INLINE $303C, $070A, $ABF2;
  196.     {$ENDC}
  197. FUNCTION SetThreadTerminator(thread: ThreadID; threadTerminator: ThreadTerminationProcPtr; terminationProcParam: UNIV Ptr): OSErr;
  198.     {$IFC NOT GENERATINGCFM}
  199.     INLINE $303C, $0611, $ABF2;
  200.     {$ENDC}
  201. FUNCTION ThreadBeginCritical: OSErr;
  202.     {$IFC NOT GENERATINGCFM}
  203.     INLINE $303C, $000B, $ABF2;
  204.     {$ENDC}
  205. FUNCTION ThreadEndCritical: OSErr;
  206.     {$IFC NOT GENERATINGCFM}
  207.     INLINE $303C, $000C, $ABF2;
  208.     {$ENDC}
  209. FUNCTION SetDebuggerNotificationProcs(notifyNewThread: DebuggerNewThreadProcPtr; notifyDisposeThread: DebuggerDisposeThreadProcPtr; notifyThreadScheduler: DebuggerThreadSchedulerProcPtr): OSErr;
  210.     {$IFC NOT GENERATINGCFM}
  211.     INLINE $303C, $060D, $ABF2;
  212.     {$ENDC}
  213. FUNCTION GetThreadCurrentTaskRef(VAR threadTRef: ThreadTaskRef): OSErr;
  214.     {$IFC NOT GENERATINGCFM}
  215.     INLINE $303C, $020E, $ABF2;
  216.     {$ENDC}
  217. FUNCTION GetThreadStateGivenTaskRef(threadTRef: ThreadTaskRef; threadToGet: ThreadID; VAR threadState: ThreadState): OSErr;
  218.     {$IFC NOT GENERATINGCFM}
  219.     INLINE $303C, $060F, $ABF2;
  220.     {$ENDC}
  221. FUNCTION SetThreadReadyGivenTaskRef(threadTRef: ThreadTaskRef; threadToSet: ThreadID): OSErr;
  222.     {$IFC NOT GENERATINGCFM}
  223.     INLINE $303C, $0410, $ABF2;
  224.     {$ENDC}
  225.  
  226. {$ALIGN RESET}
  227. {$POP}
  228.  
  229. {$SETC UsingIncludes := ThreadsIncludes}
  230.  
  231. {$ENDC} {__THREADS__}
  232.  
  233. {$IFC NOT UsingIncludes}
  234.  END.
  235. {$ENDC}
  236.